package com.klangner.go.model.impl;

import com.klangner.go.model.GameStatus;
import com.klangner.go.model.IBoard;
import com.klangner.go.model.IGameState;
import com.klangner.go.model.Move;

import junit.framework.TestCase;

public class GameStateTest extends TestCase {

	/** 
	 * Test make move
	 */
	public void testMakeMove() {
		
		IGameState	gameState = new GamesState(9, new AtariGoRules());
		
		gameState.makeMove(new Move(1, 1, IBoard.BLACK_STONE));
		
		assertEquals(IBoard.BLACK_STONE, gameState.getBoard().getStone(1, 1));
	}
	
	/**
	 * Invalid move == lost game
	 * In atari go PASS is invalid
	 */
	public void testInvalidPass(){
		IGameState	gameState = new GamesState(9, new AtariGoRules());

		gameState.makeMove(new Move(IBoard.BLACK_STONE));
		
		assertEquals(GameStatus.WHITE_WON, gameState.getStatus());
	}

	/**
	 * Invalid move == lost game
	 * Black is first move
	 */
	public void testBlackFirst(){
		IGameState	gameState = new GamesState(9, new AtariGoRules());

		// Invalid move. Black goes first
		gameState.makeMove(new Move(1, 1, IBoard.WHITE_STONE));
		
		assertEquals(GameStatus.BLACK_WON, gameState.getStatus());
	}

	/**
	 * Invalid move == lost game
	 * 2 blacks == invalid move 
	 */
	public void test2Blacks(){
		IGameState	gameState = new GamesState(9, new AtariGoRules());

		// Invalid move. Black goes first
		gameState.makeMove(new Move(1, 1, IBoard.BLACK_STONE));
		gameState.makeMove(new Move(1, 2, IBoard.BLACK_STONE));
		
		assertEquals(GameStatus.WHITE_WON, gameState.getStatus());
	}

	/**
	 * Killing stones = win 
	 * 
	 * .x..
	 * xoX.
	 * .x..
	 */
	public void testKillStones(){
		IGameState	gameState = new GamesState(9, new AtariGoRules());

		// Invalid move. Black goes first
		gameState.makeMove(new Move(1, 2, IBoard.BLACK_STONE));
		gameState.makeMove(new Move(2, 2, IBoard.WHITE_STONE));
		gameState.makeMove(new Move(3, 2, IBoard.BLACK_STONE));
		gameState.makeMove(new Move(7, 7, IBoard.WHITE_STONE));
		gameState.makeMove(new Move(2, 1, IBoard.BLACK_STONE));
		gameState.makeMove(new Move(7, 8, IBoard.WHITE_STONE));
		gameState.makeMove(new Move(2, 3, IBoard.BLACK_STONE));
		
		assertEquals(GameStatus.BLACK_WON, gameState.getStatus());
	}

}
